using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography.Xml;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace CS6238Project2.Banking.Communication
{
    /// <summary>
    /// Contains the data needed for a user to complete a transaction
    /// and for it to be recorded by the relevant entities
    /// </summary>
    [XmlRootAttribute(IsNullable = true)]
    [Serializable]
    public partial class Transaction
    {
        private string requester;//the name of the person requesting this
        private string authorizer;//the name of the authorizer
        private int account;//the account being affected
        private int adjustment;//the amount it's being changed by
        private DateTime timestamp;

        public Transaction()
        {
            requester = "";
            authorizer = "";
            account = 0;
            adjustment = 0;

        }

        public Transaction(string req, string auth, int acct, int adjust, DateTime time)
        {
            requester = req;
            authorizer = auth;
            account = acct;
            adjustment = adjust;
            timestamp = time;
        }

        /// <summary>
        /// Overloads of the == operator
        /// </summary>
        /// <param name="trans1">transaction</param>
        /// <param name="trans2">other transaction</param>
        /// <returns>true or false</returns>
        
        public static bool operator ==(Transaction trans1, Transaction trans2)
        {
            return (trans1.requester == trans2.requester)
                    &&
                    (trans1.authorizer == trans2.authorizer)
                    &&
                    (trans1.adjustment == trans2.adjustment)
                    &&
                    (trans1.account == trans2.account)
                    &&
                    (trans1.timestamp == trans2.timestamp);
        }

        public static bool operator !=(Transaction trans1, Transaction trans2)
        {
            return (trans1.requester == trans2.requester)
                    &&
                    (trans1.authorizer == trans2.authorizer)
                    &&
                    (trans1.adjustment == trans2.adjustment)
                    &&
                    (trans1.account == trans2.account)
                    &&
                    (trans1.timestamp == trans2.timestamp);
        }


        [XmlElement]
        public string Requester
        {
            get { return requester; }
            set { requester = value; }
        }
        public string Authorizer
        {
            get { return authorizer; }
            set { authorizer = value; }
        }
        public int Account
        {
            get { return account; }
            set { account = value; }
        }
        public int Adjustment
        {
            get { return adjustment; }
            set { adjustment = value;}
        }
        public DateTime Timestamp
        {
            get { return timestamp; }
            set { timestamp = value; }
        }

    }
}
